package com.cloud.pole.msg.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.msg.model.entity.SmsSendHisAdmin;
import com.cloud.pole.msg.service.SmsSendHisService;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/smsHis/admin")
@Slf4j
public class SmsAdminController {
	
	@Autowired
    private SmsSendHisService smsSendHisService;
	
	/**
	 * 分页查询短信验证码历史记录
	 * @param pageNo
	 * @param pageSize
	 * @param mobile
	 * @param templateName
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/list")
    @ResponseBody
    public ApiRestResponse<SmsSendHisAdmin> list(Integer pageNo, Integer pageSize,String mobileArea, String mobile, String templateName, String startTime, String endTime){
		pageNo = (pageNo==null||pageNo<1) ? 1 : pageNo;
		pageSize = (pageSize==null||pageSize<1) ? 10 : pageSize;

		try {
			Map<String, Object> params = new HashMap<>();
			params.put("mobileArea", mobileArea);
			params.put("mobile", mobile);
			params.put("templateName", templateName);
			params.put("startTime", startTime);
			params.put("endTime", endTime);
			PageInfo<SmsSendHisAdmin> pageInfo = smsSendHisService.selectPageSysSmsSendHisAdminList(params, pageNo, pageSize);
			return ApiRestResponse.successOfPage("成功", (int)pageInfo.getTotal(), pageInfo.getPages(), pageInfo.getPageSize(),
					pageInfo.getList());
		} catch (Exception e) {
			e.printStackTrace();
			return ApiRestResponse.fail(e.toString(), null);
		}
    }
	
}
